package experiment3;

import java.util.ArrayList;

class Person{
    String name;
    int age;
    void Initname(String person_name)
    {
        name=person_name;
    }
    void Initage(int person_age)
    {
        age=person_age;
    }
}

class ShapeArea{
    double getArea(double r)
    {
        double s=3.14*r*r;
        System.out.println(s);
        return s;
    }
    double getArea(double a,double b)
    {
        double s=a*b;
        System.out.println(s);
        return s;
    }
    double getArea(double a,double b,double h)
    {
        double s=(a+b)*h/2;
        System.out.println(s);
        return s;
    }
}

class Book{
    String title,author;
    boolean isBorrowed;
    public Book(String title, String author) {
        this.title = title;
        this.author = author;
        this.isBorrowed = false;
    }
    String Gettitle()
    {
        return title;
    }

    boolean isBorrowed()
    {
        return isBorrowed;
    }

    void setBorrowed(boolean borrowed)
    {
        this.isBorrowed=borrowed;
    }
}


class Library {
    ArrayList<Book> books=new ArrayList<>();

    void Addbook(String title, String author) {
        Book newBook = new Book(title, author);
        books.add(newBook);
    }


    void BorrowBook(String title) {
        for (Book book : books)
        {
            if (book.Gettitle().equals(title)) {
                if (!book.isBorrowed())
                {
                    book.setBorrowed(true);
                    System.out.println("《"+title+"》"+"成功借出");
                    return;
                }
                else
                {
                    System.out.println("《"+title+"》"+"已借出");
                }
            }
        }
        System.out.println("未找到该书");
    }

    void returnBook(String title)
    {
        for (Book book : books)
        {
            if (book.Gettitle().equals(title))
            {
                if(book.isBorrowed())
                {
                    book.setBorrowed(false);
                    System.out.println("《"+title+"》"+"成功还书");
                }
                else
                {
                    System.out.println("《"+title+"》"+"未被借出");
                    return;
                }
            }
        }
        System.out.println("《"+title+"》"+"未找到");
    }

}

public class experiment3 {
    public static void main(String[] args) {
        Person P1=new Person();
        Person P2=new Person();

        P1.Initname("zhangsan");
        P1.Initage(12);
        P2.Initage(10);
        P2.Initname("wangwu");
        System.out.println(P1.name+" "+P1.age +" "+P2.name+" "+P2.age);


        ShapeArea A=new ShapeArea();
        System.out.println(A.getArea(2));
        System.out.println(A.getArea(1 ,2));
        System.out.println(A.getArea(1,2,3));;

        Library library=new Library();
        library.Addbook("java","zhangsan");
        library.returnBook("java");
    }
}
